<?php
/*
 * functions.php
 *
 * Functions for the All Saints' church WordPress theme
 *
 */

/**
 * Add search to head title - not sure why WP doesn't do this automatically
 *
 * @param string $title
 * @param string $sep
 * @return string
 */
	function add_search_to_title($title, $sep=null)
	{
		if(is_search()) return($title." &raquo; Searching for '".$_GET["s"]."'");
		else return($title);
	}

	add_filter("wp_title", "add_search_to_title");

	function redirect_to_p()
	{
		global $post;

		$redirect_to = get_post_meta($post->ID, "redirect_to", true);

		if($redirect_to)
			if($location = get_permalink($redirect_to)) wp_redirect($location);
	}

	add_action("get_header", "redirect_to_p");

/**
 * Remove 'category' from category links - to display a category you need to create
 * a page using the 'Category Posts' template
 *
 * @param string $thelist
 * @return string
 */
	function remove_category_slug($thelist)
	{
		return(str_replace("category/", "", $thelist));
	}

	add_filter("the_category", "remove_category_slug");

/**
 * Add 'Parent' column to pages list
 *
 * @param array $posts_columns
 * @return array
 */
	function add_parent_column($posts_columns)
	{
		$new_posts_columns = array();

		$new_posts_columns = array_slice($posts_columns, 0, 3);
		$new_posts_columns["parent"] = __("Parent");
		$new_posts_columns = array_merge($new_posts_columns, array_slice($posts_columns, 3));

		return($new_posts_columns);
	}

	add_filter("manage_pages_columns", "add_parent_column");

/**
 * Output parent page name
 *
 * @param string $column
 * @param int $id
 */
	function add_parent_page($column, $id)
	{
		$this_post = get_post($id);
		$parent_post = get_post($this_post->post_parent);

		if($this_post->ID == $parent_post->ID):
			echo("None");
		else:
		?>
		<a href="page.php?action=edit&amp;post=<?php echo($parent_post->ID) ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $parent_post->post_title)); ?>"><?php echo $pad; echo $parent_post->post_title ?></a>
		<?php if ('private' == $parent_post->post_status) _e(' &#8212; <strong>Private</strong>'); ?>
		<?php
		endif;
	}

	add_action("manage_pages_custom_column", "add_parent_page", 10, 2);

/**
 * Returns whether or not the current browser is IE6
 *
 * @return bool
 */
	function is_ie6()
	{
		$name = $_SERVER["HTTP_USER_AGENT"];

		if(stripos($name,"msie") !== false)
		{
			$version = preg_match("|MSIE ([\d.]+)|", $name, $matches) !== 0 ? $matches[1] : null;

			if(!is_null($version) && substr($version, 0, 1) == 6) return(true);
			else return(false);
		}
	}

//
//	include js menu script file
//

	require_once("jsmenu/jsmenu.php");

?>